package com.javafactroy.kunlong.test.testservice;


import com.javafactroy.kunlong.DbAgent;
import com.javafactroy.kunlong.base.model.ReturnPageInfo;
import com.javafactroy.kunlong.data.dao.GeneralSqlMapper;
import com.javafactroy.kunlong.common.utils.CommonUtils;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.TestMethodOrder;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit.jupiter.SpringExtension;

import com.javafactroy.kunlong.data.entity.VDptempApiEntity;
import com.javafactroy.kunlong.data.service.VDptempService;
import com.github.jsonzou.jmockdata.JMockData;
import com.github.jsonzou.jmockdata.MockConfig;

import java.util.List;

/**
 * @author raymond.lei@163.com
 * @date 2023-11-13 23:03:06
 */

@SpringBootTest(classes = {DbAgent.class}, webEnvironment = SpringBootTest.WebEnvironment.NONE)
@ExtendWith(SpringExtension.class)
@Slf4j
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
@TestMethodOrder(MethodOrderer.MethodName.class)

public class VDptempTestService {

    String pkeyField = "id";

    public VDptempApiEntity mock() {
        MockConfig mockConfig = new MockConfig()
                .doubleRange(1e-9d, 11112222.99999d)
                .floatRange(1e-8f, 11111112.99999f)
                .decimalScale(52).excludes(pkeyField, "orderBys", "pageNum", "pageSize")
                .subConfig("status").intRange(0, 9).globalConfig();
        VDptempApiEntity entity = JMockData.mock(VDptempApiEntity.class, mockConfig);
        log.info("mock entity = {}", CommonUtils.toJSONString(entity));
        return entity;
    }

    @Autowired
    VDptempService service;

    @Autowired
    List<GeneralSqlMapper> list;

    @Test
    public void test001_query() {

        VDptempApiEntity param = new VDptempApiEntity();
        param.setPageSize(4).ge("departmentId", 1l);

        // param.notBetween("id", "1");
        param.gt("id",1);
        param.orderBy("dptCode", "desc").orderBy("id", "desc");

        ReturnPageInfo<VDptempApiEntity> returnPageInfo = service.query(param);
        log.info("query pageInfo = {}", CommonUtils.toJSONString(returnPageInfo));

//        JSON json = JSONUtil.parse( returnPageInfo );
//        String xml = JSONUtil.toXmlStr(json);
//        log.info("xml={}", xml);
//        FileUtil.writeUtf8String(CommonUtils.object2Xml(returnPageInfo,"result"),"e:/xxx.xml" );
    }

    @Test
    public void test002_selectByPkey() {
        VDptempApiEntity entity = service.selectByPkey(1l);
        log.info("selectByPkey entity = {}", entity);

    }

    @Test
    public void test003_selectByPkey() {
        VDptempApiEntity param = new VDptempApiEntity().setId(1);

        VDptempApiEntity entity = service.selectByPkeys(param);
        log.info("selectByPkey entity = {}", entity);

    }

    @Test
    public void test004_save() {

        VDptempApiEntity entity = mock();
        //service.save(entity.setShopName("122").setContact("ddl"));

        service.save(entity);
        log.info("save entity = {}", entity);

    }

}

